
import json

from config import config

class Cache:
    def __init__(self):
        self.cache = {}

        try:
            self.cache = json.loads( open(str(config.cache_path), "r").read() )
        except FileNotFoundError:
            ...

    def save(self):
        open(str(config.cache_path), "w").write( json.dumps(self.cache) )

    def __setitem__(self, key, value):
        self.cache[str(key)] = str(value)

    def __getitem__(self, key):
        return self.cache.get(str(key), None)
